package com.ywl.optional;

import com.ywl.entity.Author;

import java.util.Optional;
import java.util.function.Supplier;

/**
 * optional安全获取参数，抛出异常形式，orElseThrow
 * @author 24040
 * @name OptionalDemo01
 * @date 2022-08-23 16:51
 */
public class OptionalDemo02 {
    public static void main(String[] args) {
        Optional<Author> optionalAuthor = getOptionalAuthor();
        try {
            optionalAuthor.orElseThrow(() -> new RuntimeException("作家信息为空"));
        } catch (Throwable throwable) {
            throwable.printStackTrace();
        }
    }

    public static Optional<Author> getOptionalAuthor() {
        Author author = new Author
                (1L, "蒙多", 33, "一个从菜刀中明悟哲理的祖安人", null);
        return Optional.ofNullable(null);
//        return Optional.of(null);
    }
}
